#include "stdafx.h"
#include "AlphaMarkWnd.h"

CAlphaMarkWnd::CAlphaMarkWnd()
{
}

CAlphaMarkWnd::CAlphaMarkWnd(CDuiString skinName)
{
	pPlayerWall = NULL;
	if (skinName)
		mSkinFileName = skinName;
}

CAlphaMarkWnd::~CAlphaMarkWnd()
{
}

LPCTSTR CAlphaMarkWnd::GetWindowClassName() const
{
	return _T("AlphaMarkWnd");
}

CDuiString CAlphaMarkWnd::GetSkinFile()
{
	if (mSkinFileName)
		return mSkinFileName;
	else
		return _T("");
}


LRESULT CAlphaMarkWnd::HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled)
{
	//Print("AlpWnd msg:%d", uMsg);
	CDuiString SpeedText;
	switch (uMsg) {
	case USER_MSG_PLAY_PLAY:
		ShowWindow(false);
		break;
	
	case USER_MSG_PLAY_BACK:
		wParam = pow(2, wParam);
		SpeedText.Format(_T("X%d"), wParam);
		pBt_fast->SetVisible(false);
		pBt_slow->SetVisible(true);
		pBt_slow->SetText(SpeedText);
		break;

	case USER_MSG_PLAY_FAST:
		wParam = pow(2, wParam);
		SpeedText.Format(_T("X%d"), wParam);
		pBt_slow->SetVisible(false);
		pBt_fast->SetVisible(true);
		pBt_fast->SetText(SpeedText);
		break;

	case WM_SETFOCUS:	
		if(pPlayerWall)
			SetFocus(pPlayerWall->GetHWND());
		break;

	}	 
	bHandled = FALSE;
	return 0;
}

void CAlphaMarkWnd::Notify(TNotifyUI & msg)
{
}

void CAlphaMarkWnd::InitWindow()
{
	//m_pm.SetDPI(mDpi);
	pBt_fast = static_cast<CButtonUI*>(m_pm.FindControl(_T("bt_fast")));
	pBt_slow = static_cast<CButtonUI*>(m_pm.FindControl(_T("bt_slow")));

	pText = static_cast<CTextUI*>(m_pm.FindControl(_T("time")));

	//if (pText!=NULL) {
	//	pText->SetText(_T("2017-07-09 "));
	//}

	//CRect r;
	//GetWindowRect(m_hWnd, r);
	//int iWidth = GetSystemMetrics(SM_CXSCREEN);
	//::MoveWindow(m_hWnd, (iWidth - r.Width()) / 2, r.top + 784, r.Width(), r.Height(), true);
}

void CAlphaMarkWnd::SetPlayerWnd(CPlayerWallWnd *pWnd)
{
	pPlayerWall = pWnd;
}

void CAlphaMarkWnd::SetDpi(int dpi)
{
	mDpi = dpi;
}

LRESULT CAlphaMarkWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled)
{
	if (pText) {
		::SetWindowPos(m_hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
	}
	bHandled = FALSE;
	return 0;
}

void CAlphaMarkWnd::ShowTime(CString time)
{
	pText->SetText(time);
}
